<%@page import="com.cap.bts.crmdp.dealer.mars.util.PageBean"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>mars&wecare使用项目列表</title>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="core" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="validator"
	uri="http://www.springmodules.org/tags/commons-validator"%>
<core:set var="webcontext" scope="request"
	value="${pageContext.request.contextPath}" />
<core:set var="imagepath" scope="request" value="${webcontext}/images" />
<core:set var="csspath" scope="request" value="${webcontext}/css" />
<core:set var="jspath" scope="request" value="${webcontext}/javascript" />
<core:set var="jsppath" scope="request" value="${webcontext}/jsp" />
<core:set var="htmlpath" scope="request" value="${webcontext}/html" />
<core:set var="bootstrapPath" scope="request"
	value="${webcontext}/bootstrap" />
<core:set var="layerPath" scope="request" value="${webcontext}/layer" />
<!-- TODO the gdms url should replace by the token -->
<core:set var="gdmsurl" scope="request"
	value="@token-gdms.server.servlet.context.url.integration@" />
<script type="text/javascript">
	var contextPath = "${webcontext}";
</script>
<%com.cap.bts.crmdp.dealer.mars.util.PageBean pages=(com.cap.bts.crmdp.dealer.mars.util.PageBean)request.getAttribute("page");   
java.util.List<com.cap.bts.crmdp.dealer.mars.dto.ItemTypeInfoDto> list=(java.util.List<com.cap.bts.crmdp.dealer.mars.dto.ItemTypeInfoDto>)pages.getList();%>   


</head>

<script type="text/javascript">
	$(function() {
		//查询套餐信息
		$("#queryInfo_btn").click(function() {
			//设置新的页面号码

			changeToPage(1);
		});

	});


	function comfirmItemType(){
		var radios = $("input[type='radio']:checked");
		
		if(radios.length == 0){
			layer.alert('请先选择商品！', {
			    icon: 2
			})
		}
		
		var radio = $(radios[0]);
		
		
		var tr = radio.parent().parent();
		var descripton1 = tr.find("td:eq(2)").text();
		var descripton2 = tr.find("td:eq(3)").text();
		
		var objInput = $("#item_${param.itemId}");
		
		objInput.val(descripton1 + descripton2);
		
		objInput.attr("itemType", radio.attr('itemFamily'));
		objInput.attr("itemNo", radio.attr('itemCode'));
		objInput.attr("itemSource", radio.attr('itemSource'));
		
		//当你在iframe页面关闭自身时
		//var index = layer.getFrameIndex(window.name); //先得到当前iframe层的索引
		layer.close(g_itemIndex); //再执行关闭  	
	}
	
	function returnParent(){
		//当你在iframe页面关闭自身时
		//var index = layer.getFrameIndex(window.name); //先得到当前iframe层的索引
		layer.close(g_itemIndex); //再执行关闭  	
	}
	
	function changeToPage(index){
		
		//设置新的页面号码
		$("#index").val(index);
		//提交页面
		var layerIndex = layer.load(1, {
		    shade: [0.5,'#000'],
			offset : ['250px', '450px']
		});
		$.ajax({
            type: "POST",
            url : '${webcontext}/MARS/toWecareItemTypeInfoList2',
            dataType: "html",
            data: $("#search_form").serialize(),
            success: function (data) {
            	layer.close(layerIndex);
                $("#itemBox").html(data);
            },
            error: function () {
            	layer.close(layerIndex);
            	layer.alert("请求失败,请重试！", {
				    icon: 2,
				    offset : ['250px', '350px']
				});
            }
        });
	}
	
	$(function(){
		$(".table2 tbody tr").on('click',function(){
			var radio = $(this).find("input[type='radio']");
			var checkFlag = radio.prop("checked");
			if(!checkFlag){
				radio.prop("checked", true);
			}
		});
		$(".table2 tbody tr input[type='radio']").on('click',function(){
			var radio = $(this);
			radio.prop("checked", !radio.prop("checked"));
			return;
		});
	});
</script>

<style>
.icon {
	color: #FFFFFF;
}

.btnLength {
	width: 50px;
}

html, body {
overflow: auto;
}

* {
	margin: 0px;
	padding: 0px;
	font-size: 12px;
	font-family: sans-serif;
}
.table2{width:98%;margin-left:10px;}
th{white-space:nowrap;color: #FFF; background:#5CB85C;height:30px;}
td{height: 25px;}

.table2{border: 1px solid #CCC;margin-top:20px;}
.table2 tbody tr{border-bottom:1px dotted #CCC;}
.table2 tbody tr:hover{background-color:#D4E9F3;}
.table2 tr:nth-child(even){background:#F4F4F4;}
/* .table2 td:nth-child(even){color:#C00;} */


.search-box{padding-left:15px;}
.search-label{display:inline-block; width:80px;text-align:right;}
.search-box input{height:25px;width:150px;border:1px solid #CCC;}
.search-box select{height:25px;width:150px;border:1px solid #CCC;}
</style>
<body>
<form:form id="search_form" action="${webcontext}/MARS/toWecareItemTypeInfoList2" class="form-inline"
				method="post" modelAttribute="dto">
	<div>
				<div style="margin-top: 20px;">
				<input type="hidden" id="itemCode" name="itemCode" value="${dto.itemCode}">
				<input type="hidden" id="itemFamily" name="itemFamily" value="${dto.itemFamily}">
				<input type="hidden" id="itemSource" name="itemSource" value="${dto.serverCenter}">
				<input type="hidden" id="serverCenter" name="serverCenter" value="${dto.serverCenter}">
				<input type="hidden" id="itemId" name="itemId" value="${dto.itemId}">
				<input type="hidden" id="ticketId" name="ticketId"  value="${dto.ticketId}">
				<input type="hidden" id="packageId" name="packageId"  value="${dto.packageId}">
				<input type="hidden" id="ticketLineId" name="ticketLineId"  value="${dto.ticketLineId}">
				<input type="hidden" id="index" name="index"  value="${dto.index}">
				<input type="hidden" id="descripton1">
				<input type="hidden" id="descripton2">
				<div class="text-left search-box" style="margin-top: 20px;">
				          <label class="search-label"> 商品类型：</label><select name="qItemSource" >
							<option value="-1">--全部--</option>
							<option value="1"  ${dto.qItemSource eq 1  ? 'selected' :''}>非标产品</option>
							<option value="0" ${dto.qItemSource eq 0  ? 'selected' :''}>标准产品</option>
							</select>
					<label class="search-label">搜索条件<b style="color:red;">*</b>：</label><input id="searchItem" name="searchItem" value="${dto.searchItem}"/>
					
					<div style="height:10px;"></div>
					<%-- <label class="search-label">描　述：</label><input name="qDescription1" value="${dto.qDescription1}"/>
					<label class="search-label">描  述2：</label><input name="qDescription2" value="${dto.qDescription2}"/> --%>
				
					<div style="float: right; margin-top:-30px;margin-right:20px;">
					<button id="queryInfo_btn" type="button"
							class="btn btn-success btn-sm">查 询</button>					
					</div>
				</div>
				
			
				<table id="data_tabs" class="table2" >
					<thead>
						<tr >
							<th width="50px">选择</th>
							 <th width="150px">商品编号</th> 
							<th style="text-align: left;" width="45%">描述</th>
							<th style="text-align: left;" width="30%">描述2</th>
							<th style="text-align: center;">库存</th>
							<th width="100px">商品类型</th>
						</tr>
					</thead>
					<tbody>
						<core:forEach items="${itemTypeList}" var="itemlist">
							<tr>
								<td align='center'><input type="radio" name="id" class="select_one"
									value="${list.itemCode}"
									itemCode= "${itemlist.itemCode}"
									itemFamily= "${itemlist.itemFamily}"
									itemSource= "1"
									itemId= "${dto.itemId}"
									packageId= "${dto.packageId}"
									ticketId= "${dto.ticketId}"
									/></td>
 								 <td>${itemlist.itemCode}</td> 
								<td>${itemlist.description1}</td>
								<td>${itemlist.description2}</td>
								<td align='center'>${itemlist.inventory}</td>
								<td align='center'>
									<core:if test="${itemlist.itemSource==1}">非标产品</core:if>
									<core:if test="${itemlist.itemSource==0}">标准产品</core:if> 
								</td>
							</tr>
						</core:forEach>
					</tbody>
				</table>
				<div class="page_div" style="margin:10px 15px;">
				  <a href="javascript:void(0)" onClick="changeToPage(1)"><span >首页</span></a>
                   <% if(pages.getCurrentPage()>1){ %>  
                   <a href="javascript:void(0)" onClick="changeToPage(${indexs-1})"> <span >上一页</span></a>  
                   <% }%>  
                   <% if(pages.getCurrentPage()==1){ %>  
                   <a href="javascript:void(0)" onClick="changeToPage(1)"><span >上一页</span></a> 
                   <% }%>  
                   <span >页数:<%=pages.getCurrentPage() %>/<%=pages.getPageTotal()%></span> 
                   <% if(pages.getCurrentPage()<pages.getPageTotal()){ %>  
                   		<a href="javascript:void(0)" onClick="changeToPage(${indexs+1})"><span >下一页</span></a>
                   <%} %>  
                   <% if(pages.getCurrentPage()==pages.getPageTotal()){ %>  
                   		<a href="javascript:void(0)" onClick="changeToPage(<%=pages.getPageTotal()%>)"><span>下一页</span></a>  
                   <%} %>  
                   		<a href="javascript:void(0)" onClick="changeToPage(<%=pages.getPageTotal()%>)"><span >尾页</span></a> 
				</div>
				<div style="display:block;text-align:center;">
					<button type="button" class="btn" style="width: 100px;"
					 value="确认" onClick="comfirmItemType()">确 认</button>
					<button type="button" class="btn" style="width: 100px;"
					 value="返回" onClick="returnParent()">关 闭</button>
				</div>
			</div>
			<div class="spliter h_10"></div>
			<div class="spliter h_5"></div>	
	</div>
	</form:form>
</body>
</html>